package com.greyu.ysj.service.impl;



import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.greyu.ysj.config.ResultStatus;
import com.greyu.ysj.entity.CbtTransfer;
import com.greyu.ysj.entity.User;
import com.greyu.ysj.entity.CbtTransferExample;
import com.greyu.ysj.mapper.CbtTransferMapper;
import com.greyu.ysj.model.ResultModel;
import com.greyu.ysj.service.CbtTransferService;

@Service
public class CbtTransferServiceImpl implements CbtTransferService {
	@Autowired
	private CbtTransferMapper cbtTransferMapper;

	@Override
	public ResultModel save(CbtTransfer cbtTransfer) {
		try {	
			if ( cbtTransfer.getInvestId()==null
					||cbtTransfer.getUserId()==null
					||cbtTransfer.getAmount()==null
					||cbtTransfer.getFee()==null
					||cbtTransfer.getTransferType()==null
	        		) {
	            return ResultModel.error(ResultStatus.DATA_NOT_NULL);
	        }
			//insert
	        this.cbtTransferMapper.insert(cbtTransfer);
		} catch (Exception e) {
			return ResultModel.error(ResultStatus.INSERT_ERROR);
		}
	        return ResultModel.ok(cbtTransfer);
		}

	@Override
	public CbtTransfer selectByInvestId(int investId) {
		CbtTransferExample cbtTransferExample = new CbtTransferExample();
        CbtTransferExample.Criteria criteria = cbtTransferExample.createCriteria();
        criteria.andInvestIdEqualTo(investId);
        List<CbtTransfer> list = this.cbtTransferMapper.selectByExample(cbtTransferExample);

        CbtTransfer cbtTransfer;
        try {
        	cbtTransfer = list.get(0);
        } catch (Exception e) {
            return null;
        }
        return cbtTransfer;
	}


}

